package cn.tedu.coolshark.service.impl;

import cn.tedu.coolshark.mapper.LogMapper;
import cn.tedu.coolshark.pojo.Log;
import cn.tedu.coolshark.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper mapper;

    /*
      @Async描述的方法为一个异步切入点方法,
      此方法会在Spring提供的线程池中的线程上去运行
     */
    @Async
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void insert(Log log) {
        //获取当前线程及线程名
        System.out.println(Thread.currentThread().getName()+"-->LogServiceImpl.insert");
        try{Thread.sleep(5000);}catch (Exception e){} //模拟耗时时间
        System.out.println(log);
        mapper.insert(log);
    }
}
